package com.gantang.gax.engine.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * cxd引擎结果对象
 *
 * @author gantang
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class EngineResult<T> {
    private String success = "true";
    private String errorCode;
    private String errorDesc;
    private T data;

    /**
     * 构造函数
     *
     * @param t 泛型对象
     */
    public EngineResult(T t) {
        this.data = t;
    }

    /**
     * 返回成功
     *
     * @param <T> 泛型对象
     * @return 返回成功
     */
    public static <T> EngineResult<T> success() {
        return new EngineResult<>();
    }

    /**
     * 返回失败
     *
     * @param errorCode 错误编码
     * @param errorDesc 错误描述
     * @param <T>       泛型对象
     * @return 返回失败
     */
    public static <T> EngineResult<T> fail(String errorCode, String errorDesc) {
        EngineResult<T> result = new EngineResult<>();
        result.setSuccess("false");
        result.setErrorCode(errorCode);
        result.setErrorDesc(errorDesc);
        return result;
    }
}
